import React from 'react'
// ===================================================================== Temp
import Table from '#cpt/temp/Table'
import Controls from '#cpt/temp/Controls'
import Confirm from '#cpt/temp/Confirm'
import AddEditModal from '#cpt/temp/AddEditModal'
// ===================================================================== Declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const Box 		= $Lazy.load(()=>import('#tp/box/box'))
const $cache 	= $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		selectedKeys:[],
		selectedRows:[],
		// 提交表单列表
		formData : [
			{ label: '物料名称',					name: 'matl_id', 				half:true, required:true, type:'select' },
			{ label: '物料编号',  				name: 'mate_number', 			half:true, disabled:true },
			{ label: '物料分类',  				name: 'mate_type_name', 		half:true, disabled:true },
			{ label: '克隆号',  					name: 'clone_num', 				half:true, disabled:true },
			{ label: '生产商',  					name: 'mate_factory_name', 		half:true, disabled:true },
			{ label: '单个检测标本量',  			name: 'check_spec_val', 		half:true },
			{ label: '单次检测定标本量',  		name: 'check_calibration', 		half:true },
			{ label: '最优检测批次测试数',  		name: 'check_number', 			half:true },
			{ label: '单次检测质控用量',  		name: 'qty_control', 			half:true },
			{ label: '死腔量',  					name: 'dead_val', 				half:true },
			{ label: '定标频数',  				name: 'calibr_frequency', 		half:true },
			{ label: '单批次定标数(测试数)',  	name: 'calibr_check_num', 		half:true },
			{ label: '单批次质控数(测试数)',  	name: 'qc_check_num', 			half:true },
			{ label: '历史损耗量',  				name: 'history_loss', 			half:true },
			{ label: '项目复查率',  				name: 'pro_review_rate', 		half:true },
		],
	}
	
	model = {}
	
	componentDidMount(){
		const { kind_id } = this.props
		this.model = this.submit = { kind_id }
		this.fetch()
	}
	
	// 获取弹框下拉
	getModalSelect = async () => {
		const { formData } = this.state
		$fn.setModalRows(formData, [ 'matl_id' ], ()=>{
			$cache.then( async f => {
				// 获取设备名称
				$fn.setRow( formData, 'matl_id', await f.getCache({ api: 'material' }))
				//
				this.setState({ formData })
			})
		})
	}
	
	// paging
	fetch = () => $fn.fetch.call(this,'kd-material-list/index')
	
	// 表单
	cols = [
		{ title: '物料编号', 			dataIndex: 'mate_number', 			width:150 },
		{ title: '物料名称', 			dataIndex: 'mate_name', 			width:250 },
		{ title: '物料分类', 			dataIndex: 'mate_type_name', 		width:150 },
		{ title: '克隆号', 				dataIndex: 'clone_num', 			width:80 },
		{ title: '单个检测标本用量', 	dataIndex: 'check_spec_val', 		width:200 },
		{ title: '试剂生产商', 			dataIndex: 'mate_factory_name', 	width:150 },
		{ title: '最先检测批次测试数', 	dataIndex: 'check_number', 			width:100 },
	]
	// 操作按钮
	controls = () => {
		const { disabled } = this.props
		return [
			Controls.add.call(this,{click:this.getModalSelect, code:false, disabled}),
			Confirm.call(this,'删除', 'kd-material-list/del', { isKeys: true, ghost:true }),
		]
	}
	render(){
		const { disabled } = this.props
		return (
			<>
				<Box title='物料清单' controls={this.controls()} className='mt5' contentClassName='pt10'>
					{/* 表格 */}
					{ Table.call(this, { wrapStyle: this.props.tableStyle, disabled, ...this.props }) }
				</Box>
				{/* 添加 */}
				{ AddEditModal.call(this,{ title: '物料清单', labelWidth:'s11', width:'80%', api:'kd-material-list/add'}) }
			</>
		)
	}
}

export default Index